package com.hxkj.controller;

import com.hxkj.domain.po.Article;
import com.hxkj.domain.po.Column;
import com.hxkj.domain.po.ColumnArticleTree;
import com.hxkj.domain.po.Tags;
import com.hxkj.service.ColumnArticleService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * @ClassName ColumnArticeServiceController
 * @Description TODO
 * @Author Mr.zheng
 * @Date 2018/7/2 15:23
 * @Version 1.0
 */
@RestController
@RequestMapping("/columnArticle")
public class ColumnArticleController {

    @Autowired
    private ColumnArticleService columnArticleService;
    /**
     * @author Mr.zheng
     * @Description getColumnArticle 获取分类文章列表
     * @Date 15:09 2018/7/2
     **/
    @RequestMapping(value = "/getlist", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ColumnArticleTree> getColumnArticle(@RequestBody ParameterDataStruct<Column> parameterDataStruct) throws Exception{
        return () -> columnArticleService.getColumnArticle(parameterDataStruct.getData() == null ? new Column() : parameterDataStruct.getData(), parameterDataStruct.getPageTo());
    }


    /**
    * @author Mr.zheng
    * @Description getTagsArticle 获取tags标签关联的文章列表
    * @Date 17:41 2018/7/2
    **/
    @RequestMapping(value = "/gettaglist", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultPageStruct<Article>> getTagsArticle(@RequestBody ParameterDataStruct<Tags> parameterDataStruct) throws Exception{
        return () -> ResultStructUtils.buildResultPageStruct(columnArticleService.getTagsArticle(parameterDataStruct.getData() == null ? new Tags() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()),"param=value");
    }
}
